import java.util.Scanner;

public class Main1 {  
	public Main1(){
		
	}
	
    public int isMatch(String s, String p) {  
        int is = 0;  
        int ip = 0;  
          
        int press = 0;  
        int presp = 0;  
          
        boolean backstrack = false;  
        for( is = 0; is < s.length(); ){  
            if( ip == p.length()){  
                if(backstrack == false){  
                    return 0;  
                }else if(p.charAt(p.length()-1) == '*'){  
                    return 1;  
                }  
                else {  
                    ip = presp;  
                    is = ++press;  
                }  
            }  
            if(p.charAt(ip) == '?'){  
                is++;  
                ip++;  
            }else if(p.charAt(ip) == '*'){  
                presp = ++ip;  
                press = is;  
                backstrack = true;  
            }else{  
                if(p.charAt(ip) == s.charAt(is)){  
                    is++;  
                    ip++;  
                }else if(backstrack){  
                    ip = presp;  
                    is = ++press;  
                }else{  
                    return 0;  
                }  
            }  
        }  
        while(ip <= p.length() - 1 && p.charAt(ip) == '*' ){  
            ip ++;  
            if( ip == p.length()){  
                break;  
            }  
        }  
        return ip == p.length()?1:0;  
    }  
      
    public static void main(String[] args){  
        Main1 sol = new Main1();  
		Scanner scanner = new Scanner(System.in);
		String sourceString = "";
		String patternString = "";
		while(scanner.hasNextLine()){
			sourceString = scanner.nextLine();
			patternString = scanner.nextLine();
		}
		scanner.close();	
		System.out.println(sol.isMatch("qwer", "qwe*"));

    }  
}  
